const mysql = require('mysql');

// 数据库连接配置
const dbConfig = {
  host: 'localhost',
  user: 'root',
  password: '123456zxy',
  database: 'firstproject',
  port: 3306
};

// 创建连接
const connection = mysql.createConnection(dbConfig);

// 连接数据库
connection.connect((err) => {
  if (err) {
    console.error('数据库连接失败:', err.message);
    return;
  }
  console.log('数据库连接成功');
  
  // 查询最近5条教材记录，检查images字段长度
  connection.query('SELECT id, title, LENGTH(images) as images_length FROM textbooks ORDER BY created_at DESC LIMIT 5', (err, result) => {
    if (err) {
      console.error('查询教材记录失败:', err.message);
      connection.end();
      return;
    }
    
    console.log('\n最近5条教材记录:');
    if (result.length === 0) {
      console.log('没有找到教材记录');
    } else {
      result.forEach(row => {
        console.log(`ID: ${row.id}, 标题: ${row.title}, 图片数据长度: ${row.images_length || 0}`);
      });
    }
    
    // 关闭连接
    connection.end();
  });
});